package com.ysqcould.approval.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.ysqcould.approval.domain.SupplyDemand;
import com.ysqcould.approval.domain.vo.DemandVo;
import com.ysqcould.approval.mapper.SupplyDemandMapper;
import com.ysqcould.approval.service.ISupplyDemandService;
import com.ysqcould.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供需发布Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@Service
public class SupplyDemandServiceImpl implements ISupplyDemandService
{
    @Autowired
    private SupplyDemandMapper supplyDemandMapper;

    /**
     * 查询供需发布
     * 
     * @param id 供需发布主键
     * @return 供需发布
     */
    @Override
    public SupplyDemand selectSupplyDemandById(Long id)
    {
        return supplyDemandMapper.selectSupplyDemandById(id);
    }

    /**
     * 查询供需发布列表
     * 
     * @param supplyDemand 供需发布
     * @return 供需发布
     */
    @Override
    public List<DemandVo> selectSupplyDemandList(SupplyDemand supplyDemand)
    {
        final List<DemandVo> voList = supplyDemandMapper.selectSupplyDemandList(supplyDemand);
        voList.forEach(p->{
            if (ObjectUtil.isNotEmpty(p.getPcUrl())){
                final String[] url = p.getPcUrl().split(";");
                p.setPcUrlList(url);
            }
        });
        return voList;
    }

    /**
     * 新增供需发布
     * 
     * @param supplyDemand 供需发布
     * @return 结果
     */
    @Override
    public int insertSupplyDemand(SupplyDemand supplyDemand)
    {
        supplyDemand.setCreateTime(DateUtils.getNowDate());
        return supplyDemandMapper.insertSupplyDemand(supplyDemand);
    }

    /**
     * 修改供需发布
     * 
     * @param supplyDemand 供需发布
     * @return 结果
     */
    @Override
    public int updateSupplyDemand(SupplyDemand supplyDemand)
    {
        supplyDemand.setUpdateTime(DateUtils.getNowDate());
        return supplyDemandMapper.updateSupplyDemand(supplyDemand);
    }

    /**
     * 批量删除供需发布
     * 
     * @param ids 需要删除的供需发布主键
     * @return 结果
     */
    @Override
    public int deleteSupplyDemandByIds(Long[] ids)
    {
        return supplyDemandMapper.deleteSupplyDemandByIds(ids);
    }

    /**
     * 删除供需发布信息
     * 
     * @param id 供需发布主键
     * @return 结果
     */
    @Override
    public int deleteSupplyDemandById(Long id)
    {
        return supplyDemandMapper.deleteSupplyDemandById(id);
    }
}
